package org.jeecg.modules.demo.crm.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.jeecg.modules.demo.crm.entity.CProjectHeadQuotes;
import org.jeecg.modules.demo.crm.entity.CProjectQuote;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * @Description: 项目报价表
 * @Author: jeecg-boot
 * @Date:   2025-06-18
 * @Version: V1.0
 */
public interface CProjectQuoteMapper extends BaseMapper<CProjectQuote> {

    @Update("update  c_project_quote set status= #{status} where sub_project_id=#{subProjectId}  ")
    void updateStatus(@Param("subProjectId") String subProjectId, @Param("status") String status);


    @Select("select * from c_project_quote where status='审核中' and sub_project_id=#{subProjectId} limit 1 ")
    CProjectQuote quot(@Param("subProjectId") String subProjectId);

    @Select("select count(*) from c_project_quote where additional_id = #{additionalId}")
    Integer quoteRecord(@Param("additionalId") String additionalId);

    @Select("select count(*) from c_project_quote where additional_id = #{additionalId} and user_id = #{userId}")
    Integer quoteRecordByUserId(@Param("userId") String userId,@Param("additionalId") String additionalId);


    @Select("select * from c_project_quote where additional_id = #{additionalId} and user_id = #{userId}")
    List<CProjectQuote> quoteRecordByUserIdList(@Param("userId") String userId,@Param("additionalId") String additionalId);

    @Select("select * from c_project_quote  where sub_project_id=#{subProjectId} order by create_time desc limit 1")
    CProjectQuote findQuotes(@Param("subProjectId")String subProjectId);

    @Select("select count(*) from c_project_quote where sub_project_id = #{subProjectId} and status= #{status}")
    Integer findBySubProjectIdCount(@Param("subProjectId") String subProjectId , @Param("status") String status);

    @Select("select count(*) from c_project_quote where sub_project_id = #{subProjectId} ")
    Integer subProjectIdCount(@Param("subProjectId") String subProjectId );


    @Select("select * from c_project_quote where  status= #{status} and (additional_id <> '' and additional_id <> null) AND ( create_time >= DATE_SUB(NOW(), INTERVAL 1 DAY)OR update_time >= DATE_SUB(NOW(), INTERVAL 1 DAY)) ")
    List<CProjectQuote> additionalByGather(@Param("status") String status );

    @Select("select * from c_project_quote where  (status= '同意' or  status= '驳回' )and (additional_id <> '' and additional_id <> null) ")
    List<CProjectQuote> additionalByAudit();
}
